import { CopyGradeAwardBox } from "../gift/CopyGradeAwardBox";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { CopyGradeTargetBody } from "../gift/CopyGradeTargetBody";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { CopyConfig } from "../../../resource/CopyConfig";
import { Cache } from "../../../cache/Cache";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { EffectManager } from "../../../manager/EffectManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GameProxy } from "../../../mvc/GameProxy";
import { ItemData } from "../../../resource/info/ItemData";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class DailyCopyGradeTargetPane
    
    export  class DailyCopyGradeTargetPane /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int)
        {
            
            this._awardBoxs = new Vector.<CopyGradeAwardBox>();
            this._width = arg1;
            this._height = arg2;
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            ObjCreate.createBg(0, 0, this._width, this._height, this);
            ObjCreate.createBg(0, 1, 139, 24, this, ImagesConst.TileBg);
            ObjCreate.createLabel(Language.getString(90130), 8, 4, 200, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this.createAwardBox();
            var loc1=ObjCreate.createLabel(Language.getString(90131), 8, 67, 100, 20, flash.text.TextFormatAlign.LEFT, this, true);
            loc1.setStyle("textFormat", new GTextFormat(null, 14, 65315, true));
            this._numLabel = ObjCreate.createLabel("0", 68, 69, 50, 20, flash.text.TextFormatAlign.LEFT, this, true, 261667);
            this._targetsBody = new CopyGradeTargetBody();
            this._targetScrolPane = new GScrollPane();
            this._targetScrolPane.x = 8;
            this._targetScrolPane.y = 90;
            this._targetScrolPane.width = 198;
            this._targetScrolPane.height = 148;
            this._targetScrolPane.styleName = "GScrollPane";
            this._targetScrolPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._targetScrolPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._targetScrolPane.source = this._targetsBody;
            this._targetScrolPane.scrollDrag = false;
            this._targetScrolPane.focusEnabled = false;
            this.addChild(this._targetScrolPane);
            return;
        }

        /* internal  */createAwardBox(): void
        {
            var loc2=null;
            var loc1=CopyConfig.instance.getCopyGradeAllTaskAwards();
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc2 = new CopyGradeAwardBox(loc1[loc3]);
                loc2.x = 8 + loc3 * 40;
                loc2.y = 28;
                this.addChild(loc2);
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onAwardBoxClick);
                this._awardBoxs.push(loc2);
                ++loc3;
            }
            return;
        }

        public updateTargetData(): void
        {
            var loc4=null;
            var loc1=CopyConfig.instance.getCopyGradeTaskList();
            var loc2=[];
            var loc3=[];
            var loc5=0;
            var loc6=loc1;
            for(loc4 of loc6) 
            {
                if (Cache.instance.copy.checkCopyGradeTaskReach(loc4)) 
                {
                    loc2.push(loc4);
                    continue;
                }
                loc3.push(loc4);
            }
            this._numFinished = loc2.length;
            this._numLabel.htmlText = HTMLUtil.addColor(String(this._numFinished), GlobalStyle.color1);
            this._targetsBody.updateTargetInfo(loc2, loc3);
            this._targetScrolPane.update();
            this.updateBoxsStatus(loc2.length);
            return;
        }

        /* internal  */updateBoxsStatus(arg1: int): void
        {
            var loc2=false;
            var loc1=0;
            while (loc1 < this._awardBoxs.length) 
            {
                loc2 = Cache.instance.copy.checkCopyGradeTargetGot(this._awardBoxs[loc1].taskId);
                if (arg1 >= this._awardBoxs[loc1].taskNum && !loc2) 
                {
                    EffectManager.glowFilterReg(this._awardBoxs[loc1], [new Object /* flash.filters.GlowFilter */(16776960)]);
                }
                else 
                {
                    EffectManager.glowFilterUnReg(this._awardBoxs[loc1]);
                }
                if (loc2) 
                {
                    this._awardBoxs[loc1].filters = [FilterConst.colorFilter];
                }
                else 
                {
                    this._awardBoxs[loc1].filters = [];
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onAwardBoxClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as CopyGradeAwardBox;
            if (this._numFinished >= loc1.taskNum) 
            {
                GameProxy.copy.getCopyMarkReward(loc1.taskId);
            }
            return;
        }

        public onGetRewardRes(arg1: ItemData): void
        {
            var loc1=0;
            while (loc1 < this._awardBoxs.length) 
            {
                if (this._awardBoxs[loc1].rewardItemCode == arg1.itemCode) 
                {
                    LoaderManager.instance.load(arg1.itemInfo.url, this.onImgLoaded, 3, localToGlobal(new Object /* flash.geom.Point */(this._awardBoxs[loc1].x, this._awardBoxs[loc1].y)));
                    return;
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onImgLoaded(arg1: ImageInfo): void
        {
            FlyToNavbarTool.flyToBackPack(arg1.bitmapData, arg1.extData as Object /* flash.geom.Point */);
            return;
        }

        /* internal */ /* var */_width: int;

        /* internal */ /* var */_height: int;

        /* internal */ /* var */_awardBoxs: Vector.<CopyGradeAwardBox>;

        /* internal */ /* var */_numFinished: int;

        /* internal */ /* var */_numLabel: GLabel;

        /* internal */ /* var */_targetsBody: CopyGradeTargetBody;

        /* internal */ /* var */_targetScrolPane: GScrollPane;
    }
